export const selectStyle = {
	borderColor: '#86bc25', borderStyle: 'solid', borderWidth: 1
};
export const defaultPage = {
	name: '请输入名称'
};
export const defaultSimpleInfo = {
	data: [
		{
			key: '1',
			saleArea: 'USCA-南部',
			saleCount: 17384,
		},
		{
			key: '2',
			saleArea: 'USCA-中部',
			saleCount: 38653,
		},
		{
			key: '3',
			saleArea: 'USCA-西部',
			saleCount: 78253,
		},
		{
			key: '4',
			saleArea: 'USCA-东部',
			saleCount: 48452,
		},
	],
	columns: [
		{
			title: '销售区域',
			dataIndex: 'saleArea',
			key: 'saleArea',
			sortDirections: [ 'descend', 'ascend' ],
			sorter: ( a,b ) => a.saleArea - b.saleArea
		},
		{
			title: '销售数量',
			dataIndex: 'saleCount',
			key: 'saleCount',
			sortDirections: [ 'descend', 'ascend' ],
			sorter: ( a,b ) => a.saleCount - b.saleCount
		},
	]
};

// 计算合并行数
const getMergeRowNum = ( col_name, row, dataSource ) => {
	// console.log( col_name, row, dataSource );
	const temp = {};
	let n = 0;
	if ( col_name !== temp[col_name] ) {
		temp[col_name] = row[col_name];
		dataSource.forEach( ( e ) => {
			if ( e[col_name] === temp[col_name] ) {
				n += 1;
			}
		} );
	}
	// console.log( `${col_name}=${temp[col_name]}合并行数`, temp, n );
	return n;
};

const renderRow = ( value, row, index, key ) => {
	// console.log( value, row, index, key, defaultComplexInfo.data );
	const obj = {
		children: value,
		props: {
			rowSpan: null,
			colSpan: null
		},
	};
	// 与上一行不同，计算行数
	if ( ( index > 0 && row[key] !== defaultComplexInfo.data[index - 1][key] ) || index === 0 ) {
		obj.props.rowSpan = getMergeRowNum( key, row, defaultComplexInfo.data );
	} else {
		obj.props.rowSpan = 0;
	}
	return obj;
};

export const defaultComplexInfo = {
	data: [
		{ 'key': 0, 'area': '华北', 'province': '北京', 'envelope': '5653', 'paper': '7197', 'phone': '19719', 'equipment': '32371', 'chair': '48853', 'desk': '8870' },
		{ 'key': 1, 'area': '华北', 'province': '天津', 'envelope': '8870', 'paper': '4352', 'phone': '86198', 'equipment': '36552', 'chair': '41131', 'desk': '44781' },
		{ 'key': 2, 'area': '华东', 'province': '江苏', 'envelope': '634', 'paper': '1236', 'phone': '53642', 'equipment': '68365', 'chair': '5134', 'desk': '74523' },
		{ 'key': 3, 'area': '华东', 'province': '上海', 'envelope': '3231', 'paper': '9423', 'phone': '52324', 'equipment': '23475', 'chair': '4253', 'desk': '35145' },
		{ 'key': 4, 'area': '华东', 'province': '浙江', 'envelope': '4362', 'paper': '5323', 'phone': '23854', 'equipment': '85345', 'chair': '7434', 'desk': '43256' },
		{ 'key': 5, 'area': '西南', 'province': '重庆', 'envelope': '6346', 'paper': '6324', 'phone': '62634', 'equipment': '43562', 'chair': '7345', 'desk': '45245' },
	],
	columns: [
		{
			title: '',
			dataIndex: 'key',
			key: 'key',
			children: [ {
				title: '地区',
				dataIndex: 'area',
				key: 'area',
				render: ( value, row, index ) => renderRow( value, row, index, 'area' ),
			}, {
				title: '省',
				dataIndex: 'province',
				key: 'province',
				// render: ( value, row, index ) => renderRow( value, row, index, 'province' ),
			} ]
		},
		{
			title: '办公用品',
			dataIndex: 'officeSupply',
			key: 'officeSupply',
			children: [
				{
					title: '信封',
					dataIndex: 'envelope',
					key: 'envelope',
				},
				{
					title: '纸张',
					dataIndex: 'paper',
					key: 'paper',
				},
			],
		},
		{
			title: '技术',
			dataIndex: 'technology',
			key: 'technology',
			children: [
				{
					title: '电话',
					dataIndex: 'phone',
					key: 'phone',
				},
				{
					title: '设备',
					dataIndex: 'equipment',
					key: 'equipment',
				},
			],
		},
		{
			title: '家具',
			dataIndex: 'furniture',
			key: 'furniture',
			children: [
				{
					title: '椅子',
					dataIndex: 'chair',
					key: 'chair',
				},
				{
					title: '桌子',
					dataIndex: 'desk',
					key: 'desk',
				},
			],
		},
	]
};
